home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Aminet 31
/
Aminet 31 (1999)(Schatztruhe)[!][Jun 1999].iso
/
Aminet
/
util
/
arc
/
xadmaster.lha
/
xad
/
Developer
/
Sources
/
ExampleClient.c
Wrap
C/C++ Source or Header
|
1999-03-17
|
6KB
|
174 lines
#ifndef XADMASTER_EXAMPLE_C
#define XADMASTER_EXAMPLE_C
/* Programmheader
Name: Example.c
Main: xadmaster
Versionstring: $VER: Example.c 1.0 (16.02.1999)
Author: SDI
Distribution: Freeware
Description: Example disk archiver client
1.0 16.02.99 : first version
*/
#include <proto/xadmaster.h>
#include <dos/dos.h>
#include "SDI_compiler.h"
#include "xpkstuff.c"
#ifndef XADMASTERFILE
#define Example_Client FirstClient
#define NEXTCLIENT 0
UBYTE version[] = "$VER: Example 1.0 (16.02.1999)";
#endif
#define EXAMPLE_VERSION 1
#define EXAMPLE_REVISION 1
/* This is an empty example client! You should replace all "EXAMPLE"
texts with text related to your own client. */
/* NOTE: I normally use SAS-C. This compiler supports local base variables
for library calls, so all functions accessing exec function have a line like:
struct ExecBase * SysBase = xadMasterBase->xmb_SysBase;
If your compiler does not support that, insert a global base and assign it
in Example_GetInfo() function:
SysBase = xadMasterBase->xmb_SysBase;
This method is better than using address 4 (ExecBase-Pointer) directly.
Also a global version of xadMasterBase is needed. Rename the argument of the
functions to lower case xadmasterbase and add following line in
Example_GetInfo() function:
xadMasterBase = xadmasterbase;
xadMasterBase also has a pointer to DOSBase, but normally this should not
be necessary, but it is useful for debug output in test versions.
*/
/* See the included example clients as well! */
ASM(BOOL) Example_RecogData(REG(d0, ULONG size), REG(a0, STRPTR data),
REG(a6, struct xadMasterBase *xadMasterBase))
{
if(/* do some checks here (headerID, header checksum, ...) */)
return 1; /* known file */
else
return 0; /* unknown file */
}
ASM(LONG) Example_GetInfo(REG(a0, struct xadArchiveInfo *ai),
REG(a6, struct xadMasterBase *xadMasterBase))
{
/* return an error code, as long as function is empty */
return XADERR_NOTSUPPORTED;
/* Always do this function first (after RecogData). Normally it's the
easiest one.
General style for file archivers:
-Allocate "xadAllocObject(XADOBJ_FILEINFO, ...., TAG_DONE)" the
xadFileInfo structure for every file and fill it's fields with
correct values (date, size, protection, crunched size, flags, ...).
-Add the allocated structure to a linked list, which is assigned to
ai->xai_FileInfo.
-If an error occurs set "ai->xai_Flags & XADAIF_FILECORRUPT" or
return the error if it is really serious. If there are already valid
entries in linked list, there cannot be that serious!
-Leave this function.
General style for disk archivers:
-Allocate "xadAllocObject(XADOBJ_DISKINFO, ...., TAG_DONE)" the
xadDiskInfo structure for every file and fill it's fields with
correct values (tracks, heads, flags, ...).
-Add the allocated structure to a linked list, which is assigned to
ai->xai_DiskInfo.
-If there are information texts, create a linked list with xadTextInfo
structures. These are allocated with xadAllocObjectA(XADOBJ_TEXTINFO, 0).
-If an error occurs set "ai->xai_Flags & XADAIF_FILECORRUPT" or
return the error if it is really serious. If there are already valid
entries in linked list, there cannot be that serious!
-Leave this function.
For nearly all archivers it is necessary to store current file position
(ai->xai_InPos), to be able to find the data in unarchive function.
Get data using "xadHookAccess(XADAC_READ, size, buf, ai)" and seek input
data using "xadHookAccess(XADAC_INPUTSEEK, size, 0, ai)".
*/
return 0;
}
ASM(LONG) Example_UnArchive(REG(a0, struct xadArchiveInfo *ai),
REG(a6, struct xadMasterBase *xadMasterBase))
{
/* return an error code, as long as function is empty */
return XADERR_NOTSUPPORTED;
/*
-Either use ai->xai_CurDisk or ai->xai_CurFile and seek the input data
to the position required to access the archived data for the wanted entry:
"xadHookAccess(XADAC_INPUTSEEK, pos-ai->xai_InPos, 0, ai)".
-Extract the data using XADAC_READ for reads, XADAC_WRITE for storing data
or XADAC_COPY for copying the data directly.
- Leave the function either returning 0 or an errorcode, which occured.
*/
}
ASM(void) Example_Free(REG(a0, struct xadArchiveInfo *ai),
REG(a6, struct xadMasterBase *xadMasterBase))
{
/* This function needs to free all the stuff allocated in info or
unarchive function. It may be called multiple times, so clear freed
entries!
*/
/* The following example frees file and disk archive data. It assumes,
that disk archive information texts are allocated using AllocVec and all
the other stuff (file names, comments, ...) is allocated using the tags
of xadAllocObject function.
You should modify that function to meet your special requirements.
*/
struct ExecBase * SysBase = xadMasterBase->xmb_SysBase;
struct xadFileInfo *fi, *fi2;
struct xadDiskInfo *di, *di2;
struct xadTextInfo *ti, *ti2;
for(fi = ai->xai_FileInfo; fi; fi = fi2)
{
fi2 = fi->xfi_Next;
xadFreeObjectA(fi, 0);
}
ai->xai_FileInfo = 0;
for(di = ai->xai_DiskInfo; di; di = di2)
{
di2 = di->xdi_Next;
for(ti = di->xdi_TextInfo; ti; ti = ti2)
{
ti2 = ti->xti_Next;
if(ti->xti_Text)
FreeVec(ti->xti_Text);
xadFreeObjectA(ti, 0);
}
xadFreeObjectA(di, 0);
}
ai->xai_DiskInfo = 0;
}
struct xadClient Example_Client = {
NEXTCLIENT, XADCLIENT_VERSION, 1, EXAMPLE_VERSION, EXAMPLE_REVISION,
/* Here the size the client really needs to detect the filetype must be
inserted */, /* XADCF_DISKARCHIVER and/or XADCF_FILEARCHIVER */,
0 /* Type identifier. Normally should be zero */, "Example",
(BOOL (*)()) Example_RecogData, (LONG (*)()) Example_GetInfo,
(LONG (*)()) Example_UnArchive, (void (*)()) Example_Free};
#endif /* XADASTER_EXAMPLE_C */